package com.ysd.ziyuanshiyongtongji.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.ysd.ziyuanshiyongtongji.dao.IAdminDao;
import com.ysd.ziyuanshiyongtongji.model.Admin;

import com.ysd.ziyuanshiyongtongji.service.IAdminService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;

/**
 * AdminController
 */
@ApiOperation("登入列表页")
@RestController
@RequestMapping("/start/admin")
public class AdminController {
@Resource
private IAdminService adminService;
@Resource
private IAdminDao adminDao;
@RequestMapping("/login.do")
@ResponseBody
public Map login(String name,String pass,HttpSession session){
    Admin a=adminDao.login(name,pass);
    session.setAttribute("admin", a);
   Map<String,Object> map=new HashMap<String,Object>();
   if(a.getName().equals("")||!a.getName().equals(a.getName())){
       map.put("msg", "用户名错误");

   }else if(!a.getPass().equals(a.getPass())){
    map.put("msg", "密码错误");
   }else if(a.getName().equals(a.getName())&& a.getPass().equals(a.getPass())){
    map.put("msg", "登入成功");
   }
   return map;
}
@RequestMapping("/logout.do")
@ResponseBody
public Map logout(HttpSession session){
    session.invalidate();
    Map<String,Object> map=new HashMap<String,Object>();
   map.put("msg", "注销成功");
  return map;
}

}